package de.slothsoft.wasbinich.swingclient.database;

import de.slothsoft.wasbinich.core.FullPicture;
import de.slothsoft.wasbinich.core.database.DatabaseException;
import de.slothsoft.wasbinich.core.database.DatabaseExceptionCode;
import de.slothsoft.wasbinich.core.database.webservice.RestCommunicator;
import de.slothsoft.wasbinich.core.database.webservice.WebserviceManagerBean;
import de.slothsoft.wasbinich.swingclient.io.ImageUtil;

public class SwingWebserviceManagerBean extends WebserviceManagerBean {

    public SwingWebserviceManagerBean(RestCommunicator communicator) {
	super(communicator);
    }

    @Override
    protected FullPicture prepareForUpload(FullPicture picture) throws DatabaseException {
	try {
	    if (picture.section != null) {
		picture.section = ImageUtil.shrinkImageforUpload(picture.section);
	    }
	    if (picture.bigPicture != null) {
		picture.bigPicture = ImageUtil.shrinkImageforUpload(picture.bigPicture);
	    }
	    return picture;
	} catch (Exception e) {
	    throw new DatabaseException(DatabaseExceptionCode.UNKNOWN, e);
	}
    }
}
